package com.cdu.guoxinan.www.smartcom.service.impl;

import com.cdu.guoxinan.www.smartcom.domian.dto.QueryRepairManDTO;
import com.cdu.guoxinan.www.smartcom.domian.dto.UpdateRepairManDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.RepairMan;
import com.cdu.guoxinan.www.smartcom.domian.vo.SelectOption;
import com.cdu.guoxinan.www.smartcom.mapper.RepairManMapper;
import com.cdu.guoxinan.www.smartcom.service.RepairManService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class RepairManServiceImpl implements RepairManService {
    
    @Resource
    private RepairManMapper repairManMapper;
    
    @Override
    public R query(QueryRepairManDTO queryRepairManDTO) {
        // 设置分页信息
        PageHelper.startPage(queryRepairManDTO.getPage(), queryRepairManDTO.getLimit());
        List<RepairMan> list = repairManMapper.query(queryRepairManDTO);
        PageInfo pageInfo = new PageInfo(list);
        return R.ok(pageInfo.getList(), pageInfo.getTotal());
    }
    
    @Override
    public boolean add(RepairMan repairMan) {
        return repairManMapper.add(repairMan) > 0;
    }
    
    @Override
    public R update(UpdateRepairManDTO updateRepairManDTO) {
        return repairManMapper.update(updateRepairManDTO) > 0 ? R.ok() : R.error("更新失败");
    }
    
    @Override
    public boolean delete(Integer id) {
        return repairManMapper.delete(id) > 0;
    }
    
    @Override
    public RepairMan getById(Integer id) {
        return repairManMapper.getById(id);
    }

    @Override
    public List<SelectOption> getRepairManOptions() {
        List<SelectOption> selectOptions = repairManMapper.getRepairManOptions();
        return selectOptions;
    }
} 